/**
 * Created by Administrator on 2016/12/16.
 */
/*解析href*/
var str = location.search;
str = str.slice(1).split('&');
var json = {};
for (var i = 0; i < str.length; i++) {
    var a = str[i].split('=');
    json[a[0]] = a[1];
}
//console.log(json);

$(function () {
    /*初始化*/
    init();
});
var
    oUserCode = $('#userCode'),
    oShopName = $('#shopName'),
    oLegalPerson = $('#legalPerson'),
    oSearch = $('#search'),
    oEmpty = $('#empty');
var
    oUserCodeVal = '',
    oShopNameVal = '',
    oPersonVal = '';
var oUrl = `http://192.168.59.3:8082/console/shopping/matplatform?projectCode=${json.projectCode}&pageNum=1&pageSize=10`

function init(){
    $('#workTable').bootstrapTable({
        method : 'get',  //发送方式
        url : oUrl,  // 接口路径 其他工人&明细数据为空
        onLoadSuccess : function (row) {
            //oSearch.click(oSearchFun);/*点击查询函数*/
            //oEmpty.click(oEmptyFun);/*查询条件清空*/
        }
    })
}
/*按条件搜索*/
function oSearchFun(){
    oUserCodeVal = oUserCode.val();
    oShopNameVal = oShopName.val();
    oPersonVal   = oLegalPerson.val();

    oData = {
        "userCode": oUserCodeVal,
        "shopName": oShopNameVal,
        "legalPerson": oPersonVal
    };

    $.ajax({
        type : 'POST',
        url : oUrl,
        dataType : 'json',
        contentType : 'application/json',
        data:JSON.stringify(oData),
        success : function (data){
            oData1 = responseHandler(data);
            $("#workTable").bootstrapTable('load',oData1);
            /*ifrLayer($('.href-click'), oHtml);*/
        },
        error : function (err){
            console.log('错误');
        }
    })
}
function oEmptyFun(){
    oUserCode.val('');
    oShopName.val('');
    oLegalPerson.val('');
    $("#workTable").bootstrapTable('refresh',oUrl);
}
/*回调函数*/
function responseHandler(res) {
    var needData = {
        rows: res.data.list,
        total: res.data.total
    };
    return needData;
}
/*每页序号*/
function indexFmt(val,row,index){
    return index+1;
}
/*分页器*/
function workTableQuery(params){
    params["pageNum"] = (params.offset / params.limit) + 1;
    params.pageSize = params.limit;
    return params;
}
function handlerFmt(value,row){
    //console.log(row);
    return `<button onclick="getDetail('${row.userCode}','${row.shopName}','${row.legalPerson}','${row.shopId}')"><span class="icon icon-caret-down"></span></button>`
}
function getDetail(code1,code2,code3,code4){
    layer.open({
        type: 2,
        maxmin: false,
        shadeClose: false,
        closeBtn: 1,
        area : ['100%' , '100%'],
        content:`../platform-detail-c/platform-detail-c.html?projectCode=${json.projectCode}&userCode=${code1}&shopName=${code2}&legalPerson=${code3}&shopId=${code4}`,
        title :　false
    });
}


/*layer弹框效果*/
function ifrLayer (element , url){
    element.on("click", '', function() {
        layer.open({
            type: 2,
            maxmin: false,
            shadeClose: false,
            closeBtn: 1,
            area : ['100%' , '100%'],
            content:url,
            title :　false,
        });
    });
}
/*弹框*/
ifrLayer($('#ifr-worker'),`../Worker-attendance/Worker-attendance.html?projectCode=${json.projectCode}`);/*工人出勤 弹框*/
ifrLayer($('#ifr-self'),`../materiel-consume/materiel-consume.html?projectCode=${json.projectCode}`);/*平台物料 弹框*/
ifrLayer($('#pe2'),`../platform-equipment/platform-equipment.html?projectCode=${json.projectCode}`);/*平台物料-设备 弹框*/
ifrLayer($('#pf3'),`../platform-facility/platform-facility.html?projectCode=${json.projectCode}`);/*平台物料-设施 弹框*/
